<template>
	<view class="mx-referee-list">
		<view class="list-title">裁判</view>
		<view :class="['referee-item',  isSelected(index), canSelect(referee)]" v-for="(referee, index) in list" :key="referee.referee_id" @tap="onSelect(referee, index)">
			<view class="name">{{referee.referee_name}}</view>
			<view class="post">
				{{referee.post}}
			</view>
			<view class="position">
				<text>职位：</text>{{referee.position}}
			</view>
			<view class="certificate">
				<text>证书：</text>{{referee.certificate}}
			</view>
		</view>
	</view>
</template>

<script>
	import { createNamespacedHelpers, mapActions } from 'vuex'
	const { mapState, mapMutations, mapGetters } = createNamespacedHelpers('arena')
	export default {
		name:"MxRefereeList",
		props: {
			list: {
				type: Array
			},
			
			selected: {
				type: Array
			},
			
			// 已经被预订的裁判，不能选择
			booked: {
				type: Map
			},
		},
		
		data() {
			return {
				
			};
		},
		computed: {
			...mapState(['bookedReferees', 'bookedRefereesChanged']),
			...mapGetters(['bookedRefereesArr']),
			isSelected() {
				return index => {
					return this.selected.includes(index) ? 'selected': ''
				}
			},
			
			canSelect() {
				return referee => {
					for(let bookedList of this.bookedRefereesArr) {
						if(bookedList.some(bookedReferee => bookedReferee.referee_id == referee.referee_id)) {
							return 'cannot-select'
						}
					}
					
					return ''
				}
			}
		},
		methods: {
			onSelect(referee, index) {
				// 判断该裁判是否已被预订
				if(this.canSelect(referee)) {
					return
				}
				
				// 取消选择
				if(this.selected.includes(index)) {
					this.$emit('deselect', {
						index,
						price: referee.price,
						refereeId: referee.referee_id
					})
					return
				}
				
				// 选中
				this.$emit('select', {
					index,
					price: referee.price,
					refereeId: referee.referee_id
				})
			}
		}
	}
</script>

<style scoped lang="scss">
.mx-referee-list{
	display: flex;
	flex-direction: column;
	align-items: center;
	.list-title{
		align-self: center;
		display: inline-flex;
		justify-content: center;
		color: #707070;
		width: 190rpx;
		text-align: center;
		font-size: 18px;
		font-weight: bold;
		position: relative;
		margin-bottom: 80rpx;
		&::after{
			content: '';
			width: 190rpx;
			height: 10rpx;
			background-color: #3250FA;
			border-radius: 10rpx;
			position: absolute;
			left: 50%;
			bottom: -10rpx - 16rpx;
			transform: translateX(-50%);
		}
	}
	
	.referee-item{
		margin-bottom: 40rpx;
		width: 80%;
		border-radius: 6px;
		box-shadow: 0px 0px 6px 0 rgba($color: #000000, $alpha: .2);
		padding: 26rpx 30rpx;
		color: #5E657D;
		line-height: 1.5;
		.name{
			font-size: 20px;
			color: #707070;
		}
		
		.post{
			margin-top: 24rpx;
			font-size: 12px;
		}
		
		.position{
			margin-top: 18rpx;
			font-size: 14px;
			text{
				font-weight: 600;
			}
		}
		
		.certificate{
			margin-top: 18rpx;
			font-size: 14px;
			text{
				font-weight: 600;
			}
		}
		
		&.selected{
			background-image: linear-gradient(0deg, #3250FA, #826EF0);
			color: #fff;
			.name{
				color: #fff;
			}
		}
		
		&.cannot-select{
			background-color: #eee;
		}
	}
}
</style>
